package com.wlxk.message.core.service.impl;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.wlxk.base.common.util.ConvertUtil;
import com.wlxk.message.core.entity.MailTemplateDO;
import com.wlxk.message.client.dto.MailTemplateDTO;
import com.wlxk.message.client.query.MailTemplateQuery;
import com.wlxk.message.core.manager.MailTemplateManager;
import com.wlxk.message.core.service.MailTemplateService;


/**
 * @author ：wlxk
 * @since  ：2022年02月17日
 */
@Slf4j
@Service
public class MailTemplateServiceImpl implements MailTemplateService {

    @Resource
    private MailTemplateManager mailTemplateManager;

    @Override
    public List<MailTemplateDTO> queryByPage(MailTemplateQuery query) {
        return ConvertUtil.convert(mailTemplateManager.queryByPage(query), MailTemplateDTO.class);
    }

    @Override
    public MailTemplateDTO queryById(Long id) {
        return ConvertUtil.convert(mailTemplateManager.getById(id), MailTemplateDTO.class);
    }

    @Override
    public Boolean save(MailTemplateDTO mailTemplateDTO) {
        return mailTemplateManager.saveWithCreator(ConvertUtil.convert(mailTemplateDTO, MailTemplateDO.class));
    }

    @Override
    public Boolean update(MailTemplateDTO mailTemplateDTO) {
        return mailTemplateManager.updateWithOperator(ConvertUtil.convert(mailTemplateDTO, MailTemplateDO.class));
    }

    @Override
    public Boolean delete(Long id) {
        return mailTemplateManager.logicDeleteWithOperator(id);
    }

    @Override
    public MailTemplateDTO queryByCode(String code) {
        MailTemplateQuery query = new MailTemplateQuery();
        query.setTemplateCode(code);
        return ConvertUtil.convert(mailTemplateManager.getOne(query), MailTemplateDTO.class);
    }
}
